package repository

import (
	"context"
	"gitee.com/jinmingzhi/cdce-service/internal/model"
	"gitee.com/jinmingzhi/kit/rdb"
)

const (
	courseField  = "id, course_name, create_time"
	courseAllSql = "select " + courseField + " from `" + COURSE + "`"
)

type Course interface {
	FindAll(ctx context.Context) ([]*model.Course, error)
}

type CourseImpl struct {
	repo rdb.Repository
}

func NewCourse(repo rdb.Repository) Course {
	return &CourseImpl{repo: repo}
}

func (c *CourseImpl) FindAll(ctx context.Context) ([]*model.Course, error) {
	data := []*model.Course{}
	err := c.repo.FindAll(ctx, &data, courseAllSql)
	if err != nil {
		return nil, err
	}
	return data, nil
}
